package services

import (
	"cashew.com/cashew_api/dtos"
	"cashew.com/cashew_api/models"
	"cashew.com/cashew_common/configs"
	"fmt"
)

func GetSubRegionList() (*[]dtos.RegionGetSubRegionListItem, error) {

	subRegionListPtr, err := models.GetSub_region_configurationByPage(0, 200) //一次性获取200条数据, 限制总量防止异常情况

	if err != nil || subRegionListPtr == nil {
		return nil, fmt.Errorf("国家列表失败或数据为空,err=%v", err)
	}

	subRegionList := *subRegionListPtr

	if len(subRegionList) > 0 {
		for key, val := range subRegionList {
			subRegionList[key].SubRegionFlag = configs.FileHost + val.SubRegionFlag
		}
	}

	return &subRegionList, err
}
